package com.smooware.icms.util;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.preference.PreferenceManager;

/**
 * Util class designed for simple access to data from {@link SharedPreferences}.
 * 
 * @author Orest Vovchak
 */
public class PreferenceHelper {

	private PreferenceHelper() {
	}

	public static void setBooleanToPreferences(final Context context,
			final String key, final boolean value) {
		SharedPreferences preference = PreferenceManager
				.getDefaultSharedPreferences(context);

		Editor editor = preference.edit();

		editor.putBoolean(key, value);

		editor.commit();
	}

	public static boolean getBooleanFromPreferences(final Context context,
			final String key, final boolean defaultValue) {
		SharedPreferences preference = PreferenceManager
				.getDefaultSharedPreferences(context);

		return preference.getBoolean(key, defaultValue);
	}

	public static void setLongToPreferences(final Context context,
			final String key, final long value) {
		SharedPreferences preference = PreferenceManager
				.getDefaultSharedPreferences(context);

		Editor editor = preference.edit();

		editor.putLong(key, value);

		editor.commit();
	}

	public static long getLongFromPreferences(final Context context,
			final String key, final long defaultValue) {
		SharedPreferences preference = PreferenceManager
				.getDefaultSharedPreferences(context);

		return preference.getLong(key, defaultValue);
	}

	public static void setIntegerToPreferences(final Context context,
			final String key, final int value) {
		SharedPreferences preference = PreferenceManager
				.getDefaultSharedPreferences(context);

		Editor editor = preference.edit();

		editor.putInt(key, value);

		editor.commit();
	}

	public static int getIntegerFromPreferences(final Context context,
			final String key, final int defaultValue) {
		SharedPreferences preference = PreferenceManager
				.getDefaultSharedPreferences(context);

		return preference.getInt(key, defaultValue);
	}
}
